package jobs;

// 请假请求
class LeaveRequest {
    private String employeeName;
    private int days;
    public LeaveRequest(String employeeName, int days) {
        this.employeeName = employeeName;
        this.days = days;
    }
    public String getEmployeeName() {
        return employeeName;
    }
    public int getDays() {
        return days;
    }
}

// 抽象审批者
abstract class Approver {
    protected Approver next;
    public void setNext(Approver next) {
        this.next = next;
    }
    public abstract void processRequest(LeaveRequest request);
}

// 组长审批者
class TeamLeader extends Approver {
    @Override
    public void processRequest(LeaveRequest request) {
        if (request.getDays() >= 1 && request.getDays() <= 3) {
            System.out.println("组长审批：" + request.getEmployeeName() + " 请假 " + request.getDays() + " 天，审批通过。");
        } else if (next != null) {
            next.processRequest(request);
        }
    }
}

// 经理审批者
class Manager extends Approver {
    @Override
    public void processRequest(LeaveRequest request) {
        if (request.getDays() >= 4 && request.getDays() <= 7) {
            System.out.println("经理审批：" + request.getEmployeeName() + " 请假 " + request.getDays() + " 天，审批通过。");
        } else if (next != null) {
            next.processRequest(request);
        }
    }
}

// 总监审批者
class Director extends Approver {
    @Override
    public void processRequest(LeaveRequest request) {
        if (request.getDays() > 7) {
            System.out.println("总监审批：" + request.getEmployeeName() + " 请假 " + request.getDays() + " 天，审批通过。");
        } else if (next != null) {
            next.processRequest(request);
        }
    }
}

// 测试类
public class LeaveRequestChainTest {
    public static void main(String[] args) {
        Approver teamLeader = new TeamLeader();
        Approver manager = new Manager();
        Approver director = new Director();
        // 设置职责链
        teamLeader.setNext(manager);
        manager.setNext(director);

        LeaveRequest req1 = new LeaveRequest("张三", 2);
        LeaveRequest req2 = new LeaveRequest("李四", 5);
        LeaveRequest req3 = new LeaveRequest("王五", 10);

        teamLeader.processRequest(req1);
        teamLeader.processRequest(req2);
        teamLeader.processRequest(req3);
    }
}
